﻿<?php
	include 'inc/conn.php';
	$pageSize = 50;
	$phpself =$_SERVER['PHP_SELF'];
	$pagestr = end(explode("/",$phpself));
	echo "<!DOCTYPE html>\n";
?>
<html>
<head>
<title>库存管控系统(Repository Control System)</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<?
	$view=0;  /*default is list*/
	
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);
	if (isset($view))
	{
		if ($view == "1"){
			$view=1;
		}else{
			$view=0;
		}
	}

	if (!isset($page))
		$page = 1;
	
	$pageCount = 0;
	$db = new mysql();
	$db->query("select count(id) as CNT from eng_repo");
	$row = $db->fetch_assoc();
	$rowCount = $row['CNT'];
	$db->close();
	$pageCount = ceil(($rowCount/$pageSize));
	$pre = ($page-1)*$pageSize;
	
	echo '<script language="javascript">function   Go(it)   {';
	if (!isset($sort))
		echo  "window.location='$pagestr?page='+it.value;";
	else
		echo  "window.location='$pagestr?sort=$sort&page='+it.value;";
	echo "}</script>";
?>

<script type="text/javascript">  
function goTopEx() {  
    var obj = document.getElementById("goTopBtn");  
    function getScrollTop() {  
        return document.documentElement.scrollTop + document.body.scrollTop;  
    }  
    function setScrollTop(value) {  
        if (document.documentElement.scrollTop) {  
            document.documentElement.scrollTop = value;  
        } else {  
            document.body.scrollTop = value;  
        }  
    }  
    window.onscroll = function() {  
        getScrollTop() > 0 ? obj.style.display = "": obj.style.display = "none";  
    }  
    obj.onclick = function() {  
        var goTop = setInterval(scrollMove, 10);  
        function scrollMove() {  
            setScrollTop(getScrollTop() / 1.1);  
            if (getScrollTop() < 1) clearInterval(goTop);  
        }  
    }  
}  
</script>  
<style>
	BODY {  
		HEIGHT: auto;  
	}  
	#goTopBtn {  
		POSITION: fixed; TEXT-ALIGN: center; LINE-HEIGHT: 30px; WIDTH: 30px; BOTTOM: 35px; 
		HEIGHT: 33px; FONT-SIZE: 12px; CURSOR: pointer; RIGHT: 0px; _position: absolute; _right: auto  
	}  
</style>

</head>
<body class="background">
<div style="display: none" id="goTopBtn"><img border=0 src="/image/top.jpg"></div>
<script type=text/javascript>goTopEx();</script>
<?
	include "top.php";

	echo "<div class='container-fluid'>";
	echo "<div><h3><span class='label label-primary'>库存管控系统(Repository Control System)</span></h3></div>";
	echo "<div class='well'>";
	echo "<form class='form-inline'>";
	echo "<div style='form-group'>";
	if (isset($search))
		echo "搜索：<input type='text' class='form-control' name='search'   value='$search'><button type='submit' class='btn btn-info'>Search</button>";
	else
		echo "搜索：<input type='text' class='form-control' name='search'><button type='submit' class='btn btn-info'>Search</button>";
	echo "<div style='float:right'>操作：<a href='export-repo.php'><span class=\"glyphicon glyphicon-download-alt\"></span> 导出Excel</a></div>";
	echo "</form>";
	echo "</div>";
	echo "</div>";
	echo "<div>";
	echo "<table border=0 cellpadding=0 class='table table-striped'>";
 	if ($view == 0){ 
		echo '<tr class="success"><th><a href="repo_list.php?sort=kp">类型</a></th><th><a href="repo_list.php?sort=pn">料号</a></th><th>描述</th><th><a href="repo_list.php?sort=nm">数量</a></th><th><a href="repo_list.php?sort=dp">部门</a></th><th><a href="repo_list.php?sort=ow">保管人</a></th><th><a href="repo_list.php?sort=st">状态</a></th><th><a href="repo_list.php?sort=md">天数</a></th><th>备注</th></tr>';
	}
	
	$db = new mysql();
	
	if (isset($sort)){
		switch($sort){
			case "pn":
				$db->query("select * from eng_repo ORDER BY KP_PN asc limit $pre,$pageSize");
				break;
			case "kp":
				$db->query("select * from eng_repo ORDER BY KP_TYPE asc limit $pre,$pageSize");
				break;
			case "dp":
				$db->query("select * from eng_repo ORDER BY DEPT asc limit $pre,$pageSize");
				break;
			case "md":
				$db->query("select * from eng_repo ORDER BY KP_CHECKIN_DATE asc limit $pre,$pageSize");
				break;
			case "st":
				$db->query("select * from eng_repo ORDER BY STATUS asc limit $pre,$pageSize");
				break;
			case "ow":
				$db->query("select * from eng_repo ORDER BY KP_OWNER desc limit $pre,$pageSize");
				break;
			case "nm":
				$db->query("select * from eng_repo ORDER BY KP_NUM desc limit $pre,$pageSize");
				break;
			}
	}
	else
	{
		if (isset($search))
		{
			$db->query("select * from eng_repo where KP_PN like '%$search%' ORDER BY KP_CHECKIN_DATE DESC");		
		}else
			$db->query("select * from eng_repo ORDER BY KP_CHECKIN_DATE DESC limit $pre,$pageSize");
	}
	$num = $db->db_num_rows();
	for($i=0; $i<$num; $i++){
		$row = $db->fetch_assoc();
		$item = $i + 1;
		echo "<tr>";
		switch($row['KP_TYPE']){
			case "整机":
				echo "<td><font color='#0000C6'>".htmlspecialchars_decode($row['KP_TYPE'])."</font></td>";
				break;
			case "电子":
				echo "<td><font color='#FF0080'>".htmlspecialchars_decode($row['KP_TYPE'])."</font></td>";
				break;	
			case "重材":
				echo "<td><font color='#006000'>".htmlspecialchars_decode($row['KP_TYPE'])."</font></td>";
				break;	
			case "机构":
				echo "<td><font color='#842B00'>".htmlspecialchars_decode($row['KP_TYPE'])."</font></td>";
				break;		
			case "主板":
				echo "<td><font color='#600000'>".htmlspecialchars_decode($row['KP_TYPE'])."</font></td>";
				break;					
		}
		echo "<td>".htmlspecialchars_decode($row['KP_PN'])."</td>";
		echo "<td>".htmlspecialchars_decode($row['KP_DESC'])."</td>";
		echo "<td>".htmlspecialchars_decode($row['KP_NUM'])."</td>";
		echo "<td>".htmlspecialchars_decode($row['DEPT'])."</td>";
		echo "<td>".htmlspecialchars_decode($row['KP_OWNER'])."</td>";
		if ($row['STATUS'] == "借用中")
			echo "<td><font color='RED'>".htmlspecialchars_decode($row['STATUS'])."</font></td>";
		else
			echo "<td><font color='BLUE'>".htmlspecialchars_decode($row['STATUS'])."</font></td>";
	
		if(strlen(substr($row['KP_CHECKOUT_DATE'],0,10))>1)
			echo "<td>".round((strtotime(substr($row['KP_CHECKOUT_DATE'],0,10))-strtotime(substr($row['KP_CHECKIN_DATE'],0,10)))/86400)."</td>";
		else
			echo "<td>".round((strtotime(date("Y-m-d"))-strtotime(substr($row['KP_CHECKIN_DATE'],0,10)))/86400)."</td>";
		echo "<td>".htmlspecialchars_decode($row['REMARK'])."</td>";
		echo "</tr>\n";
	}
?>
		</table>
	</div>
	<? if($pageCount>1) { ?>
	<div align="center">
		<ul class='pager'>
			<li class='previous'><a href="<? echo $pagestr ?>?page=<?if($page>=2) echo $page-1; else echo $page; if(isset($sort)) echo "&sort=$sort";?>">&larr;上一页</a></li>
			第<select name="page" id="page" onchange="javascript:Go(this);">
			<? 
				for($j=1;$j<=$pageCount;$j++){
					if($j==$page)
						echo "<option value='$j' selected='$j'>$j</option>\n";
					else
						echo "<option value='$j'>$j</option>\n";
				}
			?>
			</select>页
			<li class='next'><a href="<? echo $pagestr ?>?page=<?if($page<$pageCount) echo $page+1; else echo 1; if(isset($sort)) echo "&sort=$sort";?>">下一页&rarr;</a></li>
		</ul>
	</div>
	<? } ?>
</div>
<?
include 'bottom.php';
?>
</body>
</html>
<?  
	$db->close();
?>
